/**
 * 品牌
 * 文件命名格式：zmn.模块名称.表名称.功能.jas
 * @author tanbiao
 * @since 2021/01/11
 */
layui.define(['index', 'form', 'table', 'laypage', 'layedit', 'laydate','jquery'], function (exports) {
    var $ = layui.$;
    var table = layui.table;
    var laypage = layui.laypage;
    var laydate = layui.laydate;
    var form = layui.form;
    table.init('zmn-table', {
        toolbar: "#zmn-table-tool",
        page: true,
        limit: json.pageSize,
        height: 'full-140',
        defaultToolbar: []
    });

    form.on('submit(zmn-form-reset)', function (obj) {
        form.val("zmn-difficult-ratio-filter", {
            "difficultName": "" // "name": "value"
        });
        return false;
    });

    laypage.render(layui.$.extend({limits:[10, 20, 30, 40, 50,100]},zmnPage.laypageOptions(json)));

    var ids = new Array();

    // 选择（全选或单选）
    table.on("checkbox(zmn-table)", function () {
        ids = table.checkStatus('zmn-table').data.map((item) => item.difficultId);
    });

    // 启用/停用
    table.on("toolbar(zmn-table)", function (obj) {
        if (obj.event == "del") {
            if (ids.length === 0) {
                return layer.alert("请选择至少一条数据！");
            }
            zmnPage.layStartStop(obj,"/difficult/ratio/delete.action", ids.join(","));
        } else if(obj.event == "add"){
            zmnLayUtil.openIframeCustom(layer, "/difficult/ratio/detail.action", {title: "新增难度系数", shade: 0.9, area:['690px', '400px']});
        }
        return false;
    });

    $("body").on("click", ".btn-operate", event => {
        let difficultId = $(event.target).data("id");
        zmnLayUtil.openIframeCustom(layer, "/difficult/ratio/detail.action?difficultId="+difficultId, {title: "修改难度系数", shade: 0.9, area:['690px', '400px']});
        return false;
    });

    //对外暴露的接口
    exports('serv_difficultratio_list', {});
});
